<?php
require("dbinit.php");
$indexTour = $_POST["indexTour"];

function loadProgramForm($colType,$indexResource,$thisDayIndex,$thisProgramIndex,$colTimestart,$colTimeend,$indexProgram,$indexTour) {
	$thisID = "d" . $thisDayIndex . "_p" . $thisProgramIndex;
	$colTimestart = substr($colTimestart, 0, 5);
	$colTimeend = substr($colTimeend, 0, 5);
	require("dbinit.php");
	switch ($colType) {
		case "interest":
			$query2 = "SELECT colInterestname, colInterestdescription, colInterestsite, colInterestpositiongoogle FROM tiInterestInformation WHERE indexResource=" . $indexResource;
			$selectInterest=" selected='selected'";$selectFood="";$selectActivity="";$selectHotel="";$selectTransportation="";$selectSchedule="";$selectLabel="interest";
			break;
		case "food":
			$query2 = "SELECT colFoodname, colFoodcategory, colFoodpricerange, colFooddescription, colFoodsite, colFoodpositiongoogle, colFoodaddress, colFoodtelephone, colFoodcreditecard FROM tiFoodinformation WHERE indexResource=" . $indexResource;
			$selectInterest="";$selectFood=" selected='selected'";$selectActivity="";$selectHotel="";$selectTransportation="";$selectSchedule="";$selectLabel="food";
			break;
		case "activity":
			$query2 = "SELECT colActivityname, colActivitydescription, colActivitysite, colActivityaddress, colActivitypositiongoogle, colActivitycategory FROM tiActivityinformation WHERE indexResource=" . $indexResource;
			$selectInterest="";$selectFood="";$selectActivity=" selected='selected'";$selectHotel="";$selectTransportation="";$selectSchedule="";$selectLabel="activity";
			break;
		case "hotel":
			$query2 = "SELECT colHotelname, colHotelpositiongoogle, colHoteldescription, colHotelsite, colHotelsite, colHotelcategory, colHotelstar, colHotelroomtype, colHotelprice, colHoteladdress, colHoteltelephone, colHotelcreditecard FROM tiHotelinformation WHERE indexResource=" . $indexResource;
			$selectInterest="";$selectFood="";$selectActivity="";$selectHotel=" selected='selected'";$selectTransportation="";$selectSchedule="";$selectLabel="hotel";
			break;
		case "transportation":
			$query2 = "SELECT colTransportationname, colTransportationcategory, colTransportationcompany, colTransportationsite, colTransportationdescription FROM tiTransportationInformation WHERE indexResource=" . $indexResource;
			$selectInterest="";$selectFood="";$selectActivity="";$selectHotel="";$selectTransportation=" selected='selected'";$selectSchedule="";$selectLabel="transportation";
			break;
		case "schedule":
			$query2 = "SELECT colSchedulename, colScheduledescription FROM tiScheduleinformation WHERE indexResource=" . $indexResource;
			$selectInterest="";$selectFood="";$selectActivity="";$selectHotel="";$selectTransportation="";$selectSchedule=" selected='selected'";$selectLabel="schedule";
	}	
	$result2 = mysql_query($query2, $link);
	$row2 = mysql_fetch_row($result2);

	  echo "<input type='hidden' name='indexCourse' id='indexCourse' value='$indexTour' />";
	  echo "<input type='hidden' name='indexProgram_$thisID' id='indexProgram_$thisID' value='$indexProgram' />";
	  echo "<input type='hidden' name='indexResource_$thisID' id='indexResource_$thisID' value='$indexResource' />";	
	  echo "<tr class='TourDetailDayRow'>";
	  echo "  <td class='TourDetailDayLabelNone'></td>";
	  echo "  <td><input type='text' class='myTimePicker' name='program_starttime_$thisID' id='program_starttime_$thisID' style='width:35px; border:0;' value='$colTimestart' />—<input type='text' class='myTimePicker' name='program_endtime_$thisID' id='program_endtime_$thisID' style='width:35px;border:0;' value='$colTimeend' /></td>";
	  echo "  <td><input name='program_name_$thisID' id='program_name_$thisID' type='text' style='width:98%;' value='" . $row2[0] . "' /></td>";
	  echo "  <td><select onChange='program_select(\"program_select_$thisID\");' name='program_select_$thisID' id='program_select_$thisID' style='width:98%;'><option value='null'> -- </option><option value='interest' $selectInterest>Interest</option><option value='food' $selectFood>Food</option><option value='activity' $selectActivity>Activity</option><option value='hotel' $selectHotel>Hotel</option><option value='transportation' $selectTransportation>Transportation</option><option value='schedule' $selectSchedule>Schedule</option></select>";
	  echo "  <td><div class='TourDetailProgramMore' id='TourDetailProgramMore_$thisID' style='cursor:pointer;width:15px;'>more...</div></td>";
	  echo "  <td align='right'><span class='TourDetailProgramEdit' id='TourDetailProgramEdit_$thisID' onclick='program_detail_addok_btn(\"$thisID\",\"edit\")' style='cursor: pointer;display:none;'>修改</span></td>";
	  echo "</tr>";
	  echo "<tr class='TourDetailDayRow TourDetailDayProgram'>";
	  echo "  <td class='TourDetailDayLabelNone'></td>";
	  echo "  <td>&nbsp;</td>";
	  echo "  <td colspan='4'>";
	  echo "  		<table border='0' cellspacing='0' cellpadding='1px' style='width: 100%; border-right: 1px dotted #65A6D1; border-bottom: 1px dotted #65A6D1; color:#03426A; vertical-align: text-top;'>";

	switch ($colType) {
		case "interest":		
			echo "  				<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='interest_site_$thisID' id='interest_site_$thisID' type='text' value='$row2[2]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='interest_googleurl_$thisID' id='interest_googleurl_$thisID' value='$row2[3]' style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png' name='interest_googlepreview_$thisID' id='interest_googlepreview_$thisID' class='googlepreview' onClick='googlepreview(\"interest_googlepreview_$thisID\");' /><br /><div name='interest_googlepage_$thisID' id='interest_googlepage_$thisID'><div name='interest_googlepagedetail_$thisID' id='interest_googlepagedetail_$thisID'></div></div></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='interest_description_$thisID' id='interest_description_$thisID' style='width: 98%;'>$row2[1]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='interest_refname_$thisID' id='interest_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='interest_refurl_$thisID' id='interest_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='interest_refsubmit_$thisID' id='interest_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"interest_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='interest_attachpage_$thisID' id='interest_attachpage_$thisID'></div></td></tr>";
			break;
		case "food":
			echo "  				<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='food_site_$thisID' id='food_site_$thisID' type='text' value='$row2[4]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='food_category_$thisID' id='food_category_$thisID' style='width: 98%;'><option value='$row2[1]'>$row2[1]</option><option value='Chinese Food'>Chinese Food</option><option value='Fast Food'>Fast Food</option><option value='Japanese Food'>Japanese Food</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/money_dollar.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>價格</td><td width='300px'><input name='food_pricerange_$thisID' id='food_pricerange_$thisID' type='text' value='$row2[2]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/credit_cards.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>信用卡</td><td width='300px'><input name='food_creditecard_$thisID' id='food_creditecard_$thisID' type='text' value='$row2[8]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/book_addresses.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地址</td><td width='300px'><input name='food_address_$thisID' id='food_address_$thisID' type='text' value='$row2[6]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/telephone.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>電話</td><td width='300px'><input name='food_phone_$thisID' id='food_phone_$thisID' type='text' value='$row2[7]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='food_googleurl_$thisID' id='food_googleurl_$thisID' value='$row2[5]' style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png	' name='food_googlepreview_$thisID' id='food_googlepreview_$thisID' class='googlepreview' onClick='googlepreview(\"food_googlepreview_$thisID\");' /><br /><div name='food_googlepage_$thisID' id='food_googlepage_$thisID'><div name='food_googlepagedetail_$thisID' id='food_googlepagedetail_$thisID'></div></div></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='food_description_$thisID' id='food_description_$thisID' style='width: 98%;'>$row2[3]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='food_refname_$thisID' id='food_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='food_refurl_$thisID' id='food_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='food_refsubmit_$thisID' id='food_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"food_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='food_attachpage_$thisID' id='food_attachpage_$thisID'></div></td></tr>";
			break;
		case "activity":
			echo "  				<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='activity_site_$thisID' id='activity_site_$thisID' type='text' value='$row2[2]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='activity_category_$thisID' id='activity_category_$thisID' style='width: 98%;'><option value='$row2[5]'>$row2[5]</option><option value='Dance'>Dance</option><option value='Outdoor'>Outdoor</option><option value='Seminar'>Seminar</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='activity_googleurl_$thisID' id='activity_googleurl_$thisID' value='$row2[4]' style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/map.png	' name='activity_googlepreview_$thisID' id='activity_googlepreview_$thisID' class='googlepreview' onClick='googlepreview(\"activity_googlepreview_$thisID\");' /><br /><div name='activity_googlepage_$thisID' id='activity_googlepage_$thisID'><div name='activity_googlepagedetail_$thisID' id='activity_googlepagedetail_$thisID'></div></div></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='activity_description_$thisID' id='activity_description_$thisID' style='width: 98%;'>$row2[1]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='activity_refname_$thisID' id='activity_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='activity_refurl_$thisID' id='activity_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='activity_refsubmit_$thisID' id='activity_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"activity_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='activity_attachpage_$thisID' id='activity_attachpage_$thisID'></div></td></tr>";
			break;
		case "hotel":
			echo "  				<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='hotel_site_$thisID' id='hotel_site_$thisID' type='text' value='$row2[4]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='hotel_category_$thisID' id='hotel_category_$thisID' style='width: 98%;'><option value='$row2[5]'>$row2[5]<option><option value='Hotel'>Hotel</option><option value='Motel'>Motel</option><option value='Hostel'>Hostel</option><option value='Dorm'>Dorm</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/award_star_gold.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>星等</td><td width='300px'><select name='hotel_star_$thisID' id='hotel_star_$thisID' ><option value='$row2[6]'>$row2[6]</option><option value='6'>over 5 Star</option><option value='5'>5 Star</option><option value='4'>4 Star</option><option value='3'>3 Star</option><option value='2'>2 Star</option><option value='1'>1 Star</option><option value='0'>N/A</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/house.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>房型</td><td width='300px'><select name='hotel_room_$thisID' id='hotel_room_$thisID' ><option value='$row2[7]'>$row2[7]</option><option value='1-1s'>X1, One Standard</option><option value='2-2s'>X2, Two Standard</option><option value='2-1k'>X2, One King Size</option><option value='others'>Others</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/money_dollar.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>價格</td><td width='300px'><input name='hotel_pricerange_$thisID' id='hotel_pricerange_$thisID' type='text' value='$row2[8]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/credit_cards.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>信用卡</td><td width='300px'><input name='hotel_creditecard_$thisID' id='hotel_creditecard_$thisID' type='text' value='$row2[11]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/book_addresses.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地址</td><td width='300px'><input name='hotel_address_$thisID' id='hotel_address_$thisID' type='text' value='$row2[9]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/telephone.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>電話</td><td width='300px'><input name='hotel_phone_$thisID' id='hotel_phone_$thisID' type='text' value='$row2[1]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='hotel_googleurl_$thisID' id='hotel_googleurl_$thisID' value='$row2[2]' style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png	' name='hotel_googlepreview_$thisID' id='hotel_googlepreview_$thisID' class='googlepreview' onClick='googlepreview(\"hotel_googlepreview_$thisID\");' /><br /><div name='hotel_googlepage_$thisID' id='hotel_googlepage_$thisID'><div name='hotel_googlepagedetail_$thisID' id='hotel_googlepagedetail_$thisID'></div></div></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='hotel_description_$thisID' id='hotel_description_$thisID' style='width: 98%;'>$row2[3]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='hotel_refname_$thisID' id='hotel_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='hotel_refurl_$thisID' id='hotel_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='hotel_refsubmit_$thisID' id='hotel_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"hotel_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='hotel_attachpage_$thisID' id='hotel_attachpage_$thisID'></div></td></tr>";
			break;
		case "transportation":
			echo "  				<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='transportation_site_$thisID' id='transportation_site_$thisID' type='text' value='$row2[3]' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='transportation_category_$thisID' id='transportation_category_$thisID' style='width: 98%;'><option value='$row2[1]'>$row2[1]</option><option value='Airplant'>Airplant</option><option value='Train'>Train</option><option value='Bus'>Bus</option><option value='Subway'>Subway</option><option value='Boat'>Boat</option></select></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/car.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>公司</td><td width='300px'><input type='text' name='transportation_company_$thisID' id='transportation_company_$thisID' value='$row2[2]'/></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='transportation_description_$thisID' id='transportation_description_$thisID' style='width: 98%;'>$row2[4]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='transportation_refname_$thisID' id='transportation_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='transportation_refurl_$thisID' id='transportation_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='transportation_refsubmit_$thisID' id='transportation_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"transportation_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='transportation_attachpage_$thisID' id='transportation_attachpage_$thisID'></div></td></tr>";
			break;
		case "schedule":
			echo "  				<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='schedule_description_$thisID' id='schedule_description_$thisID' style='width: 98%;'>$row2[1]</textarea></td></tr>";
			echo "  				<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='schedule_refname_$thisID' id='schedule_refname_$thisID' style='width: 98%;' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='schedule_refurl_$thisID' id='schedule_refurl_$thisID' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='schedule_refsubmit_$thisID' id='schedule_refsubmit_$thisID' class='refsubmit' value='add' onClick='refsubmit(\"schedule_refsubmit_$thisID\");' /></td></tr>";
			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='schedule_attachpage_$thisID' id='schedule_attachpage_$thisID'></div></td></tr>";
	} //end switch

			echo "  				<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'>";	
	$query3 = "SELECT colResourcelink, colResourcelinkname FROM tiResourcelink where indexResource=" . $indexResource ;
	$result3 = mysql_query($query3, $link);
	echo	"			<input type='hidden' name='" . $selectLabel . "_attachurlcount_$thisID' id='" . $selectLabel . "_attachurlcount_$thisID' value='" . mysql_num_rows($result3) . "' />";
	$thisRefIndex = 0;
	while ($row3 = mysql_fetch_assoc($result3)) {
		$thisRefIndex++;
		$divname = "link_" . $thisID . "_" . $thisRefIndex;
		//$thisText=file_get_contents($row3["colResourcelink"]);
		//preg_match('#<title>(.+)<\/title>#iU', $thisText, $thisTitle);
		//preg_match('#<body>(.+)<\/body>#iU', $thisText, $thisBody);
		//preg_match('/<img[^>]*>/Ui', $thisText, $thisImg);
		
		echo "<div name='$divname' id='$divname'>";
		echo "		<hr />Reference Name:" . $row3["colResourcelinkname"] ;
		echo "		<input type='image' class='TourDetailProgramIcon' src='img/icon/bin_closed.png' name='r$divname' id='r$divname' onclick='$(\"#$divname\").remove();' value='remove'  /><br />";
		echo "		<iframe name='p$divname' id='p$divname' src='" . $row3["colResourcelink"] . "' width='100%' heigh='200' style='border:1px'></iframe>";
		//echo "		<div name='p$divname' id='p$divname' width='100%' heigh='200' style='border:1px'>" . $thisTitle[1] . "<br />" . $thisImg[0] . "<br />" . $thisBody[1] . "</div>";
		echo "		<input type='hidden' name='colResourcelink_$divname' id='colResourcelink_$divname' value='" . $row3["colResourcelink"] . "' />";
		echo "		<input type='hidden' name='colResourcelinkname_$divname' id='colResourcelinkname_$divname' value='" . $row3["colResourcelinkname"] . "' />";
		echo "</div>";	
	}
			echo "  				</td></tr>";
  	  echo "  		</table>";
	    echo "  </td>";
	    echo "</tr>	";
	
}

$query = "SELECT ucMaintour.colEmail, ucMaintour.colTourname, ucMaintour.colDatestart, ucMaintour.colDateend, ucMaintour.colPeopleCount, ucMaintour.colTourdescription, datediff(ucMaintour.colDateend, ucMaintour.colDatestart) as diffdate, ucTourcourses.colCategory FROM ucMaintour, ucTourcourses where ucMaintour.indexTour=ucTourcourses.indexTour and ucMaintour.indexTour=" . $indexTour;
$result = mysql_query($query, $link);

if ($result) {
	$row = mysql_fetch_row($result);
	$colDatestart = $row[2];
	$colDateend = $row[3];
	$diffdate = $row[6];
	$colCategory = $row[7];
	switch  ($colCategory) {
		case "in_process":
			$colCategoryDisplay = "計畫中";
			break;
		case "share":
			$colCategoryDisplay = "分享編輯";
			break;
		case "public":
			$colCategoryDisplay = "公開閱覽";
			break;
		case "history":
			$colCategoryDisplay = "存封";
	}
	
	date_default_timezone_set('Asia/Taipei');
?>

<div id="MainTabArea" class="tabs">	
		<div id="tabs-tour">
			<input type="hidden" name="day_count" id="day_count" value="<?php if ($diffdate >= 0) {echo $diffdate+1;} else {echo "0";} ?>" /> 
			<table border="0" cellspacing="0" cellpadding="3px" style="position: relative; width: 625px; left: 5px;">
			  <tr>
			    <td width="75px" style="background-color: #3E97D1; border-bottom: 1px solid #3E97D1; color: #FFFFFF;">基本資訊</td>
			    <td colspan="5" style="border-bottom: 1px solid #3E97D1;">&nbsp;</td>
			    <td align="right" style="border-bottom: 1px solid #3E97D1;"><span id="TourInformationExpend" onclick="TourInformationExpend_click();" style="cursor:pointer;">展開 / 收合</span></td>
			  </tr>
			  <tr class="TourInformationDataRow">
			    <td width="75px" rowspan="5" valign="top" align="left"><span id="TourInformationEdit" style="cursor:pointer;">修改</span></td>
			    <td class="TourInformationField">旅遊名稱</td>
			    <td colspan="3"><input type="text" name="tour_name" id="tour_name" value="<?php echo $row[1]; ?>" disabled="disabled" style="width:100%;"/></td>
			    <td class="TourInformationField">狀態</td>
			    <td width="110px"><select name="tour_type" disabled="disabled" id="tour_type" style="width:100%;"><option value="<?php echo $colCategory;?>"><?php echo $colCategoryDisplay;?></option></option><option value="in_process">計畫中</option><option value="share">分享編輯</option><option value="public">公開閱覽</option><option value="history">存封</option></select></td>
			  </tr>
			  <tr class="TourInformationDataRow" height="1"><td height="1" colspan="6"></td></tr>
			  <tr class="TourInformationDataRow">
			    <td class="TourInformationField">開始日期</td>
			    <td width="115px"><input type="text" class="myDatePicker_tour" name="tour_startdate" id="tour_startdate" value="<?php echo date("m/d/o", strtotime($row[2])); ?>" disabled="disabled" style="width:100%;" /></td>
			    <td class="TourInformationField">結束日期</td>
			    <td width="115px"><input type="text" class="myDatePicker_tour" name="tour_enddate" id="tour_enddate" value="<?php echo date("m/d/o", strtotime($row[3])); ?>" disabled="disabled" style="width:100%;" /></td>
			    <td class="TourInformationField">人數</td>
			    <td width="110px"><input type="text" name="tour_people" id="tour_people" value="<?php echo $row[4]; ?>" disabled="disabled" style="width:100%;" /></td>
			  </tr>
			  <tr class="TourInformationDataRow" height="1"><td height="1" colspan="6"></td></tr>
			  <tr class="TourInformationDataRow">
			    <td class="TourInformationField" valign="top">描述</td>
			    <td colspan="5"><textarea rows="5" name="tour_description" id="tour_description" disabled="disabled" style="width:100%;"><?php echo $row[5]; ?></textarea></td>
			  </tr>
			  <tr class="TourInformationDataRow" height="1"><td" + myProgramID + " height="1" colspan="7"></td></tr>
			</table>
		</div>		
		<br /><br />
		<div id="tabs-details">
			<table border="0" cellspacing="0" cellpadding="3px" style="position: relative; width: 625px; left: 5px;">
			  <tr>
			    <td width="75px" style="background-color: #3E97D1; border-bottom: 1px solid #3E97D1; color: #FFFFFF;">每日行程</td>
			    <td width="110px" style="border-bottom: 1px solid #3E97D1;">&nbsp;</td>
			    <td width="200px" style="border-bottom: 1px solid #3E97D1;">&nbsp;</td>
			    <td width="125px" style="border-bottom: 1px solid #3E97D1;">&nbsp;</td>
			    <td width="45px" style="border-bottom: 1px solid #3E97D1;">&nbsp;</td>
			    <td width="70px" style="border-bottom: 1px solid #3E97D1;" align="right"><span id="TourDetailExpend" onclick="TourDetailExpend_click();" style="cursor:pointer;">開合</span></td>
			  </tr>
			<?php 
			for ($i=0;$i<=$diffdate;$i++) {
				$thisDayIndex = $i+1;
				//$query ="SELECT indexProgram FROM ucCrouseday WHERE indexCourse=$indexTour and colDay=$thisDayIndex";
				$query = "SELECT Cd.indexCourse, Cd.indexProgram, Pr.indexResource, Cd.ColDay, Pr.colType, Ps.colOrder, Ps.colTimestart, Ps.colTimeend FROM mydb.ucCrouseday Cd, mydb.ucProgramresources Pr, mydb.ucProgramschedule Ps ";
				$query .= "WHERE Cd.indexProgram=Pr.indexProgram AND Cd.indexProgram=Ps.indexProgram AND Cd.indexCourse=$indexTour AND Cd.ColDay=$thisDayIndex ";
				$query .= "ORDER BY Ps.colTimestart";
				$result = mysql_query($query, $link);
				date_default_timezone_set('Asia/Taipei');
				$showDate = new DateTime($colDatestart . " 00:00:00");
			?>
			  <input type="hidden" name="program_count_d<?php echo $thisDayIndex;?>" id="program_count_d<?php echo $thisDayIndex;?>" value="<?php if (mysql_num_rows($result) > 0) {echo mysql_num_rows($result); } else {echo "0";} ?>" /> 
			  <tr class="TourDetailDayRow" id="panelProgram_d<?php echo $thisDayIndex;?>" name="panelProgram_d<?php echo $thisDayIndex;?>">
			    <td class="TourDetailDayLabel"><?php echo $thisDayIndex;?>. <?php echo date_add($showDate,new DateInterval("P" . $i . "D"))->format("d-m-Y"); ?></td><?php  //change the 0 by count from DB?>
			    <td class="TourDetailDayHead">時間</td>
			    <td class="TourDetailDayHead">行程名稱</td>
			    <td class="TourDetailDayHead">類型</td>
			    <td class="TourDetailDayHead">&nbsp;</td>
			    <td class="TourDetailDayHead" valign="middle"><span class="TourDetailDayAddProgram" id="TourDetailDayAddProgram_d<?php echo $thisDayIndex;?>" style="cursor: pointer;"><img src="./img/icon/plugin.png" style="vertical-align: middle;" />新增行程</span></td>
			  </tr>
					<?php 
						$thisProgramIndex = 0;
						while ($row = mysql_fetch_assoc($result)) { 
							$thisProgramIndex++;
							loadProgramForm($row["colType"],$row["indexResource"],$thisDayIndex,$thisProgramIndex,$row["colTimestart"],$row["colTimeend"],$row["indexProgram"],$indexTour);?>				
						 <?php }?> 
			<?php 
			}
			?>
			</table>
		</div>


</div>
<?php 
} else {
	echo "Error :: null, exception.";
}
mysql_close($link);

?>
<script language="javascript">
$(function() {
	$(".TourDetailDayProgram").hide();
	$(".TourDetailProgramMore").click(function(){
		$(this).parent().parent().next().toggle();
		if ($(this).text() == "more...") {
			$(this).text("less...");
		} else {
			$(this).text("more...");
		}
	});

	$("#TourInformationEdit").click(function(){
		if ($(this).text() == "修改") {
			$(this).text("取消變更");
			$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").css("border","1px solid");
			$("#tabs-tour input, select, textarea").attr("disabled","");
		} else if ($(this).text() == "取消變更") {
			$(this).text("修改");
			$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").css("border","0px");
			$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").attr("disabled","disabled");
		}
		else if ($(this).text() == "送出變更")  {
			if (edit_tour_basic_information() ==true) {
				$(this).text("修改");
				$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").css("border","0px");
				$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").attr("disabled","disabled");
			}
		} 
	});
	$("#tabs-tour input,#tabs-tour select,#tabs-tour textarea").click(function(){
		$("#TourInformationEdit").text("送出變更");
	});
	
	$("#tabs-details input,#tabs-details select,#tabs-details textarea").focus(function() {
		$(this).css("border","1px solid");
	});
	$("#tabs-details input,#tabs-details select,#tabs-details textarea").blur(function() {
		$(this).css("border","0px");
	});	
	$("#tabs-details input,#tabs-details select,#tabs-details textarea").change(function(){
		myArry = $(this).attr("id").split("_");
		myID = myArry[2] + "_" + myArry[3];
		$("#TourDetailProgramEdit_" + myID).css("display","block");

	});
});
function TourInformationExpend_click() {
	$(".TourInformationDataRow").toggle();
}
function TourDetailExpend_click() {
	$(".TourDetailDayRow").toggle();
	$(".TourDetailDayProgram").hide();
}

/* Custom function: Tour > Course > Day > Program: Program Form
to Create Program Form for each day. */
$(function(){
		$(".TourDetailDayAddProgram").click(function(){
			var myDayID = $(this).attr("id").replace("TourDetailDayAddProgram_","");
			var thisProgramCount = $("#program_count_" + myDayID).attr("value");
			thisProgramCount++;
			$("#program_count_" + myDayID).attr("value",thisProgramCount);
			thisPanelProgram = "#panelProgram_" + myDayID;
			myProgramID =  myDayID + "_p" + thisProgramCount;
	
			myStr = "<tr class='TourDetailDayRow'>";
			myStr = myStr + "  <td class='TourDetailDayLabelNone'><input type='hidden' name='indexCourse' id='indexCourse' value='<?php echo $indexTour; ?>' /></td>";
			myStr = myStr + "  <td><input type='text' class='myTimePicker' name='program_starttime_" + myProgramID + "' id='program_starttime_" + myProgramID + "' style='width:35px;' />—<input type='text' class='myTimePicker' name='program_endtime_" + myProgramID + "' id='program_endtime_" + myProgramID + "' style='width:35px;' /></td>";
			myStr = myStr + "  <td><input name='program_name_" + myProgramID + "' id='program_name_" + myProgramID + "' type='text' style='width:98%;' /></td>";
			myStr = myStr + "  <td><select onChange='program_select(\"program_select_" + myProgramID + "\");' name='program_select_" + myProgramID + "' id='program_select_" + myProgramID + "' style='width:98%;'><option value='null'> -- </option><option value='interest'>Interest</option><option value='food'>Food</option><option value='activity'>Activity</option><option value='hotel'>Hotel</option><option value='transportation'>Transportation</option><option value='schedule'>Schedule</option></select>";
			myStr = myStr + "  <td><div class='TourDetailProgramMore' id='TourDetailProgramMore" + myProgramID + "' style='cursor:pointer;width:15px;'>more...</div></td>";
			myStr = myStr + "  <td align='right'><span class='TourDetailProgramEdit' id='TourDetailProgramEdit_" + myProgramID + "' onclick='program_detail_addok_btn(\"" + myProgramID + "\",\"add\")' style='cursor: pointer;'>新增</span></td>";
			myStr = myStr + "</tr>";

			$(this).parent().parent().after(myStr);
		});
});

/* Custom function: Tour > Course > Day > Program: 
to define the program type and create the form, such as interest, hotel, etc. */
function program_select(program_select_ID){

	myArry = program_select_ID.split("_");
	myID = myArry[2] + "_" + myArry[3];
	thisObj = "#" + program_select_ID;
	if ($("#" + program_select_ID).parent().parent().next().attr("class") == "TourDetailDayRow TourDetailDayProgram") {
	$("#" + program_select_ID).parent().parent().next().remove();}
	$("#" + program_select_ID).parent().parent().after("<tr class='TourDetailDayRow TourDetailDayProgram' style='display: none; '><td class='TourDetailDayLabelNone'></td><td></td><td colspan='4'></td></tr>");
	$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").append("<table border='0' cellspacing='0' cellpadding='1px' style='width: 100%; border-right: 1px dotted #65A6D1; border-bottom: 1px dotted #65A6D1; color:#03426A; vertical-align: text-top;'></table>");

	switch ($("#" + program_select_ID).val()) {
		case "interest":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='interest_site_" + myID + "' id='interest_site_" + myID + "' type='text' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='interest_googleurl_" + myID + "' id='interest_googleurl_" + myID + "' style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png' name='interest_googlepreview_" + myID + "' id='interest_googlepreview_" + myID + "' class='googlepreview' onClick='googlepreview(\"interest_googlepreview_" + myID + "\");' /><br /><div name='interest_googlepage_" + myID + "' id='interest_googlepage_" + myID + "'><div name='interest_googlepagedetail_" + myID + "' id='interest_googlepagedetail_" + myID + "'></div></div></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='interest_description_" + myID + "' id='interest_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='interest_refname_" + myID + "' id='interest_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='interest_refurl_" + myID + "' id='interest_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='interest_refsubmit_" + myID + "' id='interest_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"interest_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='interest_attachpage_" + myID + "' id='interest_attachpage_" + myID + "'></div></td></tr>");
			break;
		case "food":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='food_site_" + myID + "' id='food_site_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:25px; width:50px;'>類型</td><td width='300px'><select name='food_category_" + myID + "' id='food_category_" + myID + "'  style='width: 98%;'><option value='Chinese Food'>Chinese Food</option><option value='Fast Food'>Fast Food</option><option value='Japanese Food'>Japanese Food</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/money_dollar.png\"); background-repeat: no-repeat; padding-left:30px; width:50px;'>價格</td><td width='300px'><input name='food_pricerange_" + myID + "' id='food_pricerange_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/credit_cards.png\"); background-repeat: no-repeat; padding-left:50px; width:50px;'>信用卡</td><td width='300px'><input name='food_creditecard_" + myID + "' id='food_creditecard_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/book_addresses.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地址</td><td width='300px'><input name='food_address_" + myID + "' id='food_address_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/telephone.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>電話</td><td width='300px'><input name='food_phone_" + myID + "' id='food_phone_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='food_googleurl_" + myID + "' id='food_googleurl_" + myID + "'  style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png	' name='food_googlepreview_" + myID + "' id='food_googlepreview_" + myID + "' class='googlepreview' onClick='googlepreview(\"food_googlepreview_" + myID + "\");' /><br /><div name='food_googlepage_" + myID + "' id='food_googlepage_" + myID + "'><div name='food_googlepagedetail_" + myID + "' id='food_googlepagedetail_" + myID + "'></div></div></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='food_description_" + myID + "' id='food_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='food_refname_" + myID + "' id='food_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='food_refurl_" + myID + "' id='food_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='food_refsubmit_" + myID + "' id='food_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"food_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='food_attachpage_" + myID + "' id='food_attachpage_" + myID + "'></div></td></tr>");
			break;
		case "activity":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='activity_site_" + myID + "' id='activity_site_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='activity_category_" + myID + "' id='activity_category_" + myID + "'  style='width: 98%;'><option value='Dance'>Dance</option><option value='Outdoor'>Outdoor</option><option value='Seminar'>Seminar</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='activity_googleurl_" + myID + "' id='activity_googleurl_" + myID + "'  style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/map.png	' name='activity_googlepreview_" + myID + "' id='activity_googlepreview_" + myID + "' class='googlepreview' onClick='googlepreview(\"activity_googlepreview_" + myID + "\");' /><br /><div name='activity_googlepage_" + myID + "' id='activity_googlepage_" + myID + "'><div name='activity_googlepagedetail_" + myID + "' id='activity_googlepagedetail_" + myID + "'></div></div></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='activity_description_" + myID + "' id='activity_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='activity_refname_" + myID + "' id='activity_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='activity_refurl_" + myID + "' id='activity_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='activity_refsubmit_" + myID + "' id='activity_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"activity_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='activity_attachpage_" + myID + "' id='activity_attachpage_" + myID + "'></div></td></tr>");
			break;
		case "hotel":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='hotel_site_" + myID + "' id='hotel_site_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='hotel_category_" + myID + "' id='hotel_category_" + myID + "'  style='width: 98%;'><option value='Hotel'>Hotel</option><option value='Motel'>Motel</option><option value='Hostel'>Hostel</option><option value='Dorm'>Dorm</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/award_star_gold.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>星等</td><td width='300px'><select name='hotel_star_" + myID + "' id='hotel_star_" + myID + "' ><option value='6'>over 5 Star</option><option value='5'>5 Star</option><option value='4'>4 Star</option><option value='3'>3 Star</option><option value='2'>2 Star</option><option value='1'>1 Star</option><option value='0'>N/A</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/house.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>房型</td><td width='300px'><select name='hotel_room_" + myID + "' id='hotel_room_" + myID + "' ><option value='1-1s'>X1, One Standard</option><option value='2-2s'>X2, Two Standard</option><option value='2-1k'>X2, One King Size</option><option value='others'>Others</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/money_dollar.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>價格</td><td width='300px'><input name='hotel_pricerange_" + myID + "' id='hotel_pricerange_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/credit_cards.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>信用卡</td><td width='300px'><input name='hotel_creditecard_" + myID + "' id='hotel_creditecard_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/book_addresses.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地址</td><td width='300px'><input name='hotel_address_" + myID + "' id='hotel_address_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/telephone.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>電話</td><td width='300px'><input name='hotel_phone_" + myID + "' id='hotel_phone_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/map.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>地圖</td><td width='300px'><input type='text' name='hotel_googleurl_" + myID + "' id='hotel_googleurl_" + myID + "'  style='width: 80%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/magnifier.png	' name='hotel_googlepreview_" + myID + "' id='hotel_googlepreview_" + myID + "' class='googlepreview' onClick='googlepreview(\"hotel_googlepreview_" + myID + "\");' /><br /><div name='hotel_googlepage_" + myID + "' id='hotel_googlepage_" + myID + "'><div name='hotel_googlepagedetail_" + myID + "' id='hotel_googlepagedetail_" + myID + "'></div></div></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='hotel_description_" + myID + "' id='hotel_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='hotel_refname_" + myID + "' id='hotel_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='hotel_refurl_" + myID + "' id='hotel_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='hotel_refsubmit_" + myID + "' id='hotel_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"hotel_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='hotel_attachpage_" + myID + "' id='hotel_attachpage_" + myID + "'></div></td></tr>");
			break;
		case "transportation":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/world.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>網站</td><td width='300px'><input name='transportation_site_" + myID + "' id='transportation_site_" + myID + "' type='text'  style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/tag_blue.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>類型</td><td width='300px'><select name='transportation_category_" + myID + "' id='transportation_category_" + myID + "'  style='width: 98%;'><option value='Airplant'>Airplant</option><option value='Train'>Train</option><option value='Bus'>Bus</option><option value='Subway'>Subway</option><option value='Boat'>Boat</option></select></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/car.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>公司</td><td width='300px'><input type='text' name='transportation_company_" + myID + "' id='transportation_company_" + myID + "' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='transportation_description_" + myID + "' id='transportation_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='transportation_refname_" + myID + "' id='transportation_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='transportation_refurl_" + myID + "' id='transportation_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='transportation_refsubmit_" + myID + "' id='transportation_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"transportation_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='transportation_attachpage_" + myID + "' id='transportation_attachpage_" + myID + "'></div></td></tr>");
			break;
		case "schedule":
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/comments.png\"); background-repeat: no-repeat; padding-left:20px; width:50px; vertical-align: text-top;'>描述</td><td width='300px'><textarea rows='3' name='schedule_description_" + myID + "' id='schedule_description_" + myID + "' style='width: 98%;'></textarea></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='background-image: url(\"./img/icon/link.png\"); background-repeat: no-repeat; padding-left:20px; width:50px;'>參考名稱</td><td width='300px'><input type='text' name='schedule_refname_" + myID + "' id='schedule_refname_" + myID + "' style='width: 98%;' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>參考網址</td><td width='300px'><input type='text' name='schedule_refurl_" + myID + "' id='schedule_refurl_" + myID + "' style='width: 85%;' /><input type='image' class='TourDetailProgramIcon' src='img/icon/application_add.png' name='schedule_refsubmit_" + myID + "' id='schedule_refsubmit_" + myID + "' class='refsubmit' value='add' onClick='refsubmit(\"schedule_refsubmit_" + myID + "\");' /></td></tr>");
			$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><div name='schedule_attachpage_" + myID + "' id='schedule_attachpage_" + myID + "'></div></td></tr>");
	}
	$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table:nth-child(1)").append("<tr><td style='padding-left:20px; width:50px;'>&nbsp;</td><td width='300px'><input type='hidden' name='" + $("#" + program_select_ID).val() + "_attachurlcount_" + myID + "' id='" + $("#" + program_select_ID).val() + "_attachurlcount_" + myID + "' value='0' /></td></tr>");	

	
	$("#" + program_select_ID).parent().parent().next().find("td:nth-child(3)").find("table input:text,table select,table textarea").css("border","1px solid");
	$("#" + program_select_ID).parent().next().find("div:first").text("less...");
	$("#" + program_select_ID).parent().parent().next().show();
}

/* Custom function: Tour > Course > Day > Program: Form:
to show the google map on the web through program form. */
function googlepreview(thisID){
	myArry = thisID.split("_");
	thisDetail = "#" + myArry[0] + "_googlepagedetail_" + myArry[2] + "_" + myArry[3] ;                                                                            				
	thisPage =  "#" + myArry[0] + "_googlepage_" + myArry[2] + "_" + myArry[3] ;
	thisURL = "#" + myArry[0] + "_googleurl_" + myArry[2] + "_" + myArry[3] ;
	$(thisDetail).remove();
	$(thisPage).append("<div name='" + thisDetail + "' id='" + thisDetail + "'>" + $(thisURL).attr("value") + "</div>");
	}

/* Custom function: Tour > Course > Day > Program: From:
to load the reference site on the web through program form. */
function refsubmit(thisID){
	myArry = thisID.split("_");
	thisCount = "#" + myArry[0] + "_attachurlcount_" + myArry[2] + "_" + myArry[3] ;
	thisPage = "#" + myArry[0] + "_attachpage_" + myArry[2] + "_" + myArry[3] ;
	thisRefname = "#" + myArry[0] + "_refname_" + myArry[2] + "_" + myArry[3] ;
	thisRefURL = "#" + myArry[0] + "_refurl_" + myArry[2] + "_" + myArry[3] ;
	if ($(thisRefURL).attr("value")=="") return;
	var myRefIndex = $(thisCount).attr("value");
	myRefIndex ++;
	$(thisCount).attr("value",myRefIndex) ;
	divname = "link_" +  myArry[2] + "_" + myArry[3] + "_" + myRefIndex; 
	$(thisPage).append("<div name='" + divname + "' id='" + divname + "'><div>");
	
	$("#" + divname).append("<hr />Reference Name:" + $(thisRefname).attr("value"));
	$("#" + divname).append("<input type='image' src='img/icon/bin_closed.png' name='r" + divname + "' id='r" + divname + "' onclick='$(\"#" + divname + "\").remove();' value='remove'  /><br />");
	$("#" + divname).append("<iframe name='p" + divname + "' id='p" + divname + "' src='" + $(thisRefURL).attr("value") + "' width='100%' heigh='200' style='border:1px'></iframe>");
	$("#" + divname).append("<input type='hidden' name='colResourcelink_" + divname + "' id='colResourcelink_" + divname + "' value='" + $(thisRefURL).attr("value") + "' />");
	$("#" + divname).append("<input type='hidden' name='colResourcelinkname_" + divname + "' id='colResourcelinkname_" + divname + "' value='" + $(thisRefname).attr("value") + "' />");
}

function edit_tour_basic_information() {
	//alert("!@#");
		$.post("main_edit_tour_basic_process.php",{
			indexTour:<?php echo $indexTour; ?>,
			tour_name: $("#tour_name").attr("value"),
			tour_startdate: $("#tour_startdate").attr("value"),
			tour_enddate: $("#tour_enddate").attr("value"),
			tour_people: $("#tour_people").attr("value"),
			tour_description: $("#tour_description").attr("value"),
			tour_category: $("#tour_type").attr("value")
		},
		function(data) {
			//alert("<?php echo $indexTour; ?>" + data);
			if (data == "true") {
				alert("Tour basic information is modified successfully.");
			} else if (data == "false") {
				alert("Edit fail, data are not changed. Please try again.");
			}
		});
		return true;
		//window.location.reload();
}


function program_detail_addok_btn(thisID,thisAction) {
	thisLabel = $("#program_select_" + thisID).val();
	colResourcelink = "";
	colResourcelinkname = "";
	for (i=1;i<=$("#" + thisLabel + "_attachurlcount_" + thisID).val();i++) {
		colResourcelink = colResourcelink + $("#colResourcelink_link_" + thisID + "_" + i).val() + ",";
		colResourcelinkname = colResourcelinkname + $("#colResourcelinkname_link_" + thisID + "_" + i).val() + ",";
	}
	colResourcelink = colResourcelink.substring(0,colResourcelink.length-1);
	colResourcelinkname = colResourcelinkname.substring(0,colResourcelinkname.length-1);
	$.post("main_edit_program_process.php", {
		thisID: thisID,
		indexCourse: <?php echo $indexTour;?>,
		indexProgram: $("#indexProgram_" + thisID).val(),
		indexResource: $("#indexResource_" + thisID).val(),
		action: thisAction,
		colResourcelink: colResourcelink,
		colResourcelinkname: colResourcelinkname,
		program_select: $("#program_select_" + thisID).val(),
		program_name: $("#program_name_" + thisID).val(),
		program_starttime: $("#program_starttime_" + thisID).val(),
		program_endtime: $("#program_endtime_" + thisID).val(),
		site: $("#" + thisLabel + "_site_" + thisID).val(),
		googleurl: $("#" + thisLabel + "_googleurl_" + thisID).val(),
		attachurlcount: $("#" + thisLabel + "_attachurlcount_" + thisID).val(),
		description: $("#" + thisLabel + "_description_" + thisID).val(),
		category: $("#" + thisLabel + "_category_" + thisID).val(),
		pricerange: $("#" + thisLabel + "_pricerange_" + thisID).val(),
		creditecard: $("#" + thisLabel + "_creditecard_" + thisID).val(),
		address: $("#" + thisLabel + "_address_" + thisID).val(),
		phone: $("#" + thisLabel + "_phone_" + thisID).val(),
		hotel_star: $("#hotel_star_" + thisID).val(),
		hotel_room: $("#hotel_room_" + thisID).val(),
		transportation_company: $("#transportation_company_" + thisID).val()
		}, 
		function(data) {
			if (data == "true") {
				$("#TourDetailProgramEdit_" + thisID).css("display","none");
				window.location.reload();
			} else {alert(data);}
	});
	
}
</script>